var express = require('express');
var path = require('path');

var app = express();

// serve our static stuff like index.css
// app.use(express.static(path.join(__dirname, 'public')));

var ReactDOMServer = require('react-dom/server');
var React = require('react');
var ServerComponent = require("./ServerComponent.js");

// send all requests to index.html so browserHistory works
app.get('*', function (req, res) {
    var text = ReactDOMServer.renderToString(<ServerComponent />);
    var html = "<!DOCTYPE html><html><head><meta charset='UTF-8'></head><body><div>" + text + "</div></body></html>";
    res.setHeader("Content-Type", 'text/html;charset=utf-8');
    // console.log(html);
    res.send(html);
})

var PORT = 8000;
app.listen(PORT, function() {
    console.log('Production Express server running at localhost:' + PORT)
});

// https://facebook.github.io/react/docs/react-dom-server.html#rendertostring
